﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;

public partial class admin_tax_edit : SiteAdminBasePage
{
    public int _stateTaxId;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            uccSTATE_DESC.DataBind();
            uccSTATE_STS.DataBind();
            LoadData();
        }
    }
    private void LoadData()
    {
        int stateTaxId = 0;
        if (!string.IsNullOrEmpty(Request.QueryString["sid"]) &&
            int.TryParse(Request.QueryString["sid"], out stateTaxId))
        {
            TblTax stateTax = TblTax.GetTblTaxByTaxId(stateTaxId);
            this.BindData(stateTax);
            _stateTaxId = stateTaxId;
        }

    }
    private void BindData(TblTax stateTax)
    {
        if (stateTax != null)
        {
            STAX_CODETextBox.Text = stateTax.STAX_CODE.Trim();
            STAX_DESCTextBox.Text = stateTax.STAX_DESC.Trim();
            TAX_FRTDropDown.SelectedValue= stateTax.TAX_FRT.Trim();
            VERTEX_UPDT_DATETextBox.Text =ECommerce.Library.ECommerce.Utility.FormatDateTime(stateTax.VERTEX_UPDT_DATE);
            VERTEX_UPDT_NUMTextBox.Text = stateTax.VERTEX_UPDT_NUM.Trim();
            VERTEX_EFF_DATETextBox.Text = stateTax.VERTEX_EFF_DATE.Trim();
            STAX_P_ATextBox.Text = stateTax.STAX_P_A.Trim();
            ACCR_S_ATextBox.Text = stateTax.ACCR_S_A.Trim();
            CITY_STSTextBox.Text = stateTax.CITY_STS.Trim();
            AR5_UNUSED_1TextBox.Text = stateTax.AR5_UNUSED_1.Trim();
            ZIP_STSTextBox.Text = stateTax.ZIP_STS.Trim().Trim();
            if (!string.IsNullOrEmpty(stateTax.STATE_STS))
                uccSTATE_STS.SelectedValue = stateTax.STATE_STS.Trim();
            COUNTY_STSTextBox.Text = stateTax.COUNTY_STS.Trim();
            AR5_UNUSED_2TextBox.Text = stateTax.AR5_UNUSED_2.Trim();
            COUNTY_CODE_STSTextBox.Text = stateTax.COUNTY_CODE_STS.Trim();
            if (!string.IsNullOrEmpty(stateTax.TF_STATE))
                TF_STATEDropDown.SelectedValue = stateTax.TF_STATE.Trim();
            if (!string.IsNullOrEmpty(stateTax.TF_COUNTY))
                TF_COUNTYDropDown.SelectedValue = stateTax.TF_COUNTY.Trim();
            if (!string.IsNullOrEmpty(stateTax.TF_CITY))
                TF_CITYDropDown.SelectedValue = stateTax.TF_CITY.Trim();

            if (!string.IsNullOrEmpty(stateTax.STATE_DESC))
                uccSTATE_DESC.SelectedValue=stateTax.STATE_DESC.Trim();
            NO_OVRDE_T_CTextBox.Text = stateTax.NO_OVRDE_T_C.Trim();
            TOTAL_TAXTextBox.Text = stateTax.TOTAL_TAX.Trim();
            AR5_UNUSED_3TextBox.Text = stateTax.AR5_UNUSED_3.Trim();
            STAX_RATETextBox.Text = stateTax.STAX_RATE.ToString();
            MAX_STAXTextBox.Text = stateTax.MAX_STAX.ToString();
            COUNTY_TAX_IF_OTHERTextBox.Text = stateTax.COUNTY_TAX_IF_OTHER.ToString();
            STATE_TAX_IF_OTHERTextBox.Text = stateTax.STATE_TAX_IF_OTHER.ToString();
            ST_STAX_RATETextBox.Text = stateTax.ST_STAX_RATE.ToString();
            CNTY_STAX_RATETextBox.Text = stateTax.CNTY_STAX_RATE.ToString();
            MAX_OTHERTextBox.Text = stateTax.MAX_OTHER.ToString();
            TAX_RATE_TOTALTextBox.Text = stateTax.TAX_RATE_TOTAL.ToString();
            USE_CANADATextBox.Text = stateTax.USE_CANADA.Trim();
            TAX_TAXTextBox.Text = stateTax.TAX_TAX.Trim();
            TAX_SPL_CHGTextBox.Text = stateTax.TAX_SPL_CHG.Trim();

        }
    }
    protected void UpdateButton_Click(object sender, EventArgs e)
    {
        int stateTaxId = 0;
        if (!string.IsNullOrEmpty(Request.QueryString["sid"]) &&
            int.TryParse(Request.QueryString["sid"], out stateTaxId))
        {

            if (stateTaxId > 0)
            {
                TblTax _tax = TblTax.GetTblTaxByTaxId(stateTaxId);
                if (_tax != null)
                {
                    _tax.STAX_CODE = STAX_CODETextBox.Text.Trim();
                    _tax.STAX_DESC = STAX_DESCTextBox.Text.Trim();
                    _tax.TAX_FRT = TAX_FRTDropDown.SelectedValue;
                    _tax.VERTEX_UPDT_DATE = Convert.ToDateTime(VERTEX_UPDT_DATETextBox.Text.Trim());
                    _tax.VERTEX_UPDT_NUM = VERTEX_UPDT_NUMTextBox.Text.Trim();
                    _tax.VERTEX_EFF_DATE = VERTEX_EFF_DATETextBox.Text.Trim();
                    _tax.STAX_P_A = STAX_P_ATextBox.Text.Trim();
                    _tax.ACCR_S_A = ACCR_S_ATextBox.Text.Trim();
                    _tax.CITY_STS = CITY_STSTextBox.Text.Trim();
                    _tax.AR5_UNUSED_1 = AR5_UNUSED_1TextBox.Text.Trim();
                    _tax.ZIP_STS = ZIP_STSTextBox.Text.Trim();
                    _tax.STATE_STS = uccSTATE_STS.SelectedValue;
                    _tax.COUNTY_STS = COUNTY_STSTextBox.Text.Trim();
                    _tax.AR5_UNUSED_2 = AR5_UNUSED_2TextBox.Text.Trim();
                    _tax.COUNTY_CODE_STS = COUNTY_CODE_STSTextBox.Text.Trim();
                    _tax.TF_STATE = TF_STATEDropDown.SelectedValue;
                    _tax.TF_COUNTY = TF_COUNTYDropDown.SelectedValue;
                    _tax.TF_CITY = TF_CITYDropDown.SelectedValue;
                    _tax.STATE_DESC = uccSTATE_DESC.SelectedValue;
                    _tax.NO_OVRDE_T_C = NO_OVRDE_T_CTextBox.Text.Trim();
                    _tax.TOTAL_TAX = TOTAL_TAXTextBox.Text.Trim();
                    _tax.AR5_UNUSED_3 = AR5_UNUSED_3TextBox.Text.Trim();
                    _tax.STAX_RATE = Convert.ToDouble(STAX_RATETextBox.Text.Trim());
                    _tax.MAX_STAX = Convert.ToDouble(MAX_STAXTextBox.Text.Trim());
                    _tax.COUNTY_TAX_IF_OTHER = Convert.ToDouble(COUNTY_TAX_IF_OTHERTextBox.Text.Trim());
                    _tax.STATE_TAX_IF_OTHER = Convert.ToDouble(STATE_TAX_IF_OTHERTextBox.Text.Trim());
                    _tax.ST_STAX_RATE = Convert.ToDouble(ST_STAX_RATETextBox.Text.Trim());
                    _tax.CNTY_STAX_RATE = Convert.ToDouble(CNTY_STAX_RATETextBox.Text.Trim());
                    _tax.MAX_OTHER = Convert.ToDouble(MAX_OTHERTextBox.Text.Trim());
                    _tax.TAX_RATE_TOTAL = Convert.ToDouble(TAX_RATE_TOTALTextBox.Text.Trim());
                    _tax.USE_CANADA = USE_CANADATextBox.Text.Trim();
                    _tax.TAX_TAX = TAX_TAXTextBox.Text.Trim();
                    _tax.TAX_SPL_CHG = TAX_SPL_CHGTextBox.Text.Trim();
                    // 
                    if (TblTax.UpdateTblTax(_tax))
                    {
                        uccResponseMessage.Visible = true;
                        uccResponseMessage.SetSuccessMessage("Updated Succesfully");
                    }
                    else 
                    {
                        uccResponseMessage.Visible = true;
                        uccResponseMessage.SetSuccessMessage("Update Failed!");
                    }
                }
            }
        }

    }
}